<html layout:decorate="~{project/objectManage/object_list}" xmlns:layout="http://www.w3.org/1999/xhtml">
<div layout:fragment="object_list">

    <style>
        .search-data{
            width: 150px;
        }
    </style>

    <div class="main-body">
        <div style="width: 1270px;height: 50px">
            <div class="search_condition" style="width: 860px;float: left">
                <form id="search-form">
                    <input class="search-data" name="Q_LIKE_name" type="text" placeholder="名称" >
                    <select class="search-data" name="Q_EQ_equipmentType">
                        <option value="">设备类型</option>
                        <option value="1">变流器</option>
                        <option value="2">电池包</option>
                        <option value="3">电池组</option>
                        <option value="4">电池单体</option>
                    </select>

                    <button type="button" id="search-btn" class="btn btn-primary btn-search"
                            onclick="search('dataTable')">搜索
                    </button>
                </form>
            </div>

            <div id="toolbar" class="btn-group btn-group-sm"style="width: 300px; margin-top: 11px;margin-left: 40px">
            <a type="button" class="btn btn-primary" onclick="editData('/project/objectManage/message_list', 'id', null , 'modal1')">查看报文数据列表</a>
            <a type="button" class="btn btn-info" onclick="editData('/project/objectManage/equipment_code_edit', 'id', null , 'modal2')">唯一标识</a>
        </div>
        </div>

        <table id="dataTable" data-url="/project/objectManage/equipment_data" data-page-list=[]  data-striped="true"
               data-pagination="true" data-page-size="10" data-cache="false" data-toolbar-align="right"></table>


        <script>
            var dataFormat_equipment = [{
                checkbox: true
            },{
                field:'id',
                title:'id',
                visible:false
            },{
                field: 'code',
                title: '唯一标识'
            }, {
                field: 'name',
                title: '名称'
            },{
                field: 'project.name',
                title: '所属项目'
            }, {
                field: 'equipmentType',
                title: '设备类型',
                formatter : function (value, row, index) {
                    switch (value){
                        case "1":
                            return "变流器";
                        case "2":
                            return "电池包";
                        case "3":
                            return "电池组";
                        case "4":
                            return "电池单体";
                    }
                }
            }, {
                field: 'communication',
                title: '通信类型'
            }, {
                field: 'messageName',
                title: '报文配置文件'
            }];
            window.onload = function () {
                getTable("search-data",dataFormat_equipment, "dataTable");
            };
            /**************************条件搜索**********************/
            function getTable(searchClass, dataFormat, id) {
                $("#" + id).bootstrapTable({
                    method: "get",
                    sidePagination: "server",
                    dataType: "json",
                    queryParams: function queryParams(params) {   //设置查询参数
                        var param = {
                            pageNum: params.offset / params.limit
                        };
                        $("." + searchClass).each(function () {
                            var key = $(this).attr("name");
                            var val = $(this).val();
                            console.log(key+"===="+val);
                            param[key] = val;
                        });
                        //  console.log(param);
                        return param;
                    },
                    columns: dataFormat_equipment
                });
            }
            function search(id) {
                $("#" + id).bootstrapTable("selectPage", 1);
            }
        </script>
    </div>
</div>
</html>

